﻿package mortal.game.view.mainUI.shortcutbar.exSkill
{
    import Message.DB.Tables.*;
    import mortal.component.gconst.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.systemSetting.*;
    import mortal.mvc.core.*;

    public class ExSkillShortcutBarCache extends Object
    {
        private var _obj:Object;
        private var _lastKeyDownPos:int = -1;
        public var isLastKeyByClick:Boolean = false;
        public var isLocked:Boolean = false;
        public var isShowCDTime:Boolean = true;

        public function ExSkillShortcutBarCache()
        {
            this._obj = {};
            return;
        }// end function

        public function get lastKeyDownPos() : int
        {
            return this._lastKeyDownPos;
        }// end function

        public function set lastKeyDownPos(param1:int) : void
        {
            this._lastKeyDownPos = param1;
            return;
        }// end function

        public function initData(param1:String) : void
        {
            if (param1 == null || param1 == "")
            {
                return;
            }
            this._obj = JSON.parse(param1);
            return;
        }// end function

        public function get shortcutBarDatas() : Object
        {
            return this._obj;
        }// end function

        public function addShortCut(param1:String, param2:int, param3:int, param4:Object) : void
        {
            this._obj[param1 + "_" + param2] = {t:param3, v:param4};
            var _loc_5:Object = {pos:param2, t:param3, v:param4};
            Dispatcher.dispatchEvent(new DataEvent(EventName.ShortExCutBarDataChange, _loc_5));
            return;
        }// end function

        public function getData(param1:String, param2:int) : Object
        {
            return this._obj[param1 + "_" + param2];
        }// end function

        public function removeShortcut(param1:String, param2:int) : void
        {
            this._obj[param1 + "_" + param2] = null;
            delete this._obj[param1 + "_" + param2];
            return;
        }// end function

        public function removeShortcutByPetAndSkill(param1:String, param2:int = 0) : void
        {
            var _loc_3:TSkill = null;
            var _loc_4:Object = null;
            if (param2 > 0)
            {
                _loc_3 = SkillConfig.instance.getInfoById(param2);
            }
            var _loc_5:int = 0;
            while (_loc_5 < GameConst.PetBreakCopyMaxSkill)
            {
                
                _loc_4 = this.getData(param1, _loc_5);
                if (_loc_4 && (_loc_3 == null || _loc_3 && _loc_3.series == _loc_4.v))
                {
                    this.removeShortcut(param1, _loc_5);
                    if (_loc_3)
                    {
                        break;
                    }
                }
                _loc_5++;
            }
            this.save();
            return;
        }// end function

        public function save() : void
        {
            var _loc_1:Object = {};
            _loc_1["type"] = SystemSettingType.ExSkillShortcutBarData;
            _loc_1["value"] = JSON.stringify(this._obj);
            Dispatcher.dispatchEvent(new DataEvent(EventName.SystemSettingSava, _loc_1));
            return;
        }// end function

        public function cleanAll() : void
        {
            var _loc_1:Object = {};
            _loc_1["type"] = SystemSettingType.ExSkillShortcutBarData;
            _loc_1["value"] = "";
            Dispatcher.dispatchEvent(new DataEvent(EventName.SystemSettingSava, _loc_1));
            return;
        }// end function

    }
}
